/******************************************************************************
Project    : Real time rtsp server library base on live555
*******************************************************************************
File Name    :  <VideoRTimeServerMediaSubsession.h>:  video real time SMSS head file
Module Name  :  
Description  :  None
History      :
 No.   Ver.     Date        Designed by  Comment
-----+--------+----------+------------+---------------------------------------
 001   0.00.01  06/05/2015  <3G@LIURENHUA>   <video real time SMSS head file>
*******************************************************************************/
#ifndef _VIDEO_RTIME_SERVER_MEDIA_SUBSESSION_H
#define _VIDEO_RTIME_SERVER_MEDIA_SUBSESSION_H

#include <liveMedia.hh>
#ifdef LOCAL_SOCK_INPUT
#include <LocalUdpSocket.h>
#endif /* LOCAL_SOCK_INPUT */

#include "RealTimeRtspServer_common.h"
/******************************************************************************
  class declaration
 ******************************************************************************/
class 
VideoRTimeServerMediaSubsession : public OnDemandServerMediaSubsession
{
public:
	/* Create new server media session object */
	static VideoRTimeServerMediaSubsession * createNew(
							UsageEnvironment & env,
							const tEsFmt eCodecId = VIDEO_FORMAT_H264,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity = NULL,
#endif /* LOCAL_SOCK_INPUT */
							const u_int8_t ucFrmRate = FRAME_PER_SEC,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize = 0, 
							const u_int32_t unRBufSize = 0
#else
							queue_t *pstQue = NULL
#endif /* LOCAL_SOCK_INPUT */
							);

	void afterPlayingDummy1();
	void chkForAuxSDPLine1();

protected:
	VideoRTimeServerMediaSubsession(
							UsageEnvironment & env, 
							const tEsFmt eCodecId,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity,
#endif /* LOCAL_SOCK_INPUT */
							const u_int8_t ucFrmRate,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize, 
							const u_int32_t unRBufSize
#else
							queue_t *pstQue
#endif /* LOCAL_SOCK_INPUT */
							);
	virtual ~VideoRTimeServerMediaSubsession(void);

	virtual char const * getAuxSDPLine(
		RTPSink * rtpSink, FramedSource * inputSource);
	/* "estBitrate" is the stream's estimated bitrate, in kbps */
	virtual FramedSource * createNewStreamSource(
		unsigned clientSessionId, unsigned & estBitrate); 
	virtual RTPSink * createNewRTPSink(
		Groupsock * rtpGroupsock, 
		unsigned char rtpPayloadTypeIfDynamic, 
		FramedSource * inputSource);
	void setDoneFlag() { m_cDoneFlag = ~0; }

private:
#ifdef LOCAL_SOCK_INPUT
	/* Save local socket identity */
	char m_cIdentity[LSOCK_ID_LENGTH];
#else
	queue_t *m_que;
#endif /* LOCAL_SOCK_INPUT */
	/* RTP sink pointer */
	RTPSink * m_pDummyRTPSink;
	/* SDP line pointer */
	char * m_pSDPLine;
	/* Done flag */
	char m_cDoneFlag;
	/* Codec identity */
	tEsFmt m_eCodecId;
	/* Frame per second */
	u_int8_t m_ucFrmRate;
	/* Local socket send buffer size */
	u_int32_t m_unSBufSize;
	/* Local socket receive buffer size */
	u_int32_t m_unRBufSize;
};
#endif /* _VIDEO_RTIME_SERVER_MEDIA_SUBSESSION_H */
